package algorithm;

/**
 * 二分查找非递归
 */
public class BinarySortNoRecursion {

  public static void main(String[] args) {
    int[] arr={2,5,8,90,345,567};
      int index = binarySort(arr, 10);
    System.out.println(index);
  }

  public static int binarySort(int[] arr,int value){
      int low=0;
      int high=arr.length;
      while (low<=high){
          int mid=(low+high)/2;
          if (arr[mid]==value){
              return mid;
          }else if (arr[mid]>value){
              high=mid-1;
          }else {
              low=mid+1;
          }
      }
      return -1;
  }
}
